﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text; 

namespace WarsKeyChanger
{
    public class IniFileInfo
    {
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);


        public string FilePath { get; private set; }
        public IniFileInfo(string filePath)
        {
            FilePath = filePath;
            if (!System.IO.File.Exists(filePath))
            {
                System.IO.File.Create(filePath,1024, System.IO.FileOptions.Asynchronous); 
            }
        } 

        public string GetSectionKeyValue(string sectionName,string key)
        { 
            StringBuilder retVal = new StringBuilder(500);
            var i = GetPrivateProfileString(sectionName, key, "", retVal, 500, this.FilePath);
            return retVal.ToString();
        }

        public void SetSectionKeyValue(string sectionName, string key, string value)
        {
            WritePrivateProfileString(sectionName, key, value, this.FilePath);
        }

    }


    
}
